<%@ page language="java" import="java.util.*,org.json.*,org.dom4j.*,java.io.*,sun.misc.*" pageEncoding="UTF-8"%>
<%! 
//配置变量
  String servurl = "http://172.16.4.74:8080/order_inside";
  
//ftp服务器参数
String _ftp_ip = "172.16.4.74";
int _ftp_port = 21;
String _ftp_userid = "longjian";
String _ftp_pwd = "scmis*08";


//String _ftp_ip = "10.100.150.179";
//int _ftp_port = 21;
//String _ftp_userid = "sprocftp";
//String _ftp_pwd = "sprocftp#123";


 
public JSONObject getPropertes(){
	JSONObject retJson= new JSONObject();
	try{
		//retJson.put("business_url", "http://172.16.4.74:8080/BLBE");
		retJson.put("business_url", "http://172.16.8.121:9191/mobile");
		retJson.put("download", "/mobilecontorl/downloadDB");
		retJson.put("upload", "/mobilecontorl/uploadDB");
		retJson.put("checkServer", "/mobilecontorl/checkServer");
		retJson.put("flag", true);
	}catch(Exception e){
		System.out.println(e);
	}
	return retJson;
}

//jsonp处理
public String jsonp(String callbakstr,String jsonstr) throws Exception{
  return (((callbakstr==null)||(callbakstr.trim()==""))?jsonstr:callbakstr+"("+jsonstr+")");
}
public String  getUUID(){
	return UUID.randomUUID().toString().replaceAll("-", "");
}

//xml字符串转json，非加密
public JSONObject Xmlstr2Json(String xmlstr){
	   JSONObject xmljson  = new JSONObject();
	   try{
	       Document doc = DocumentHelper.parseText("<result>"+xmlstr+"</result>");
	       xmljson = elementToJson(doc.getRootElement());
	   }catch(Exception e){
		  System.out.println(e);
	   }
	   return xmljson;
}

public JSONObject elementToJson(Element node) throws Exception{
	 JSONObject result = new JSONObject();
	  List<Attribute> listAttr = node.attributes();
	  for(Attribute attr:listAttr){
		  result.put(attr.getName(),  attr.getValue() );
	  }
	  List<Element> listElement = node.elements();
	  if(!listElement.isEmpty()){
		  for(Element e:listElement){
			  if(e.attributes().isEmpty() && e.elements().isEmpty()){
				  result.put(e.getName(), e.getTextTrim());
			  }else{
				  if(!result.has(e.getName()))
					  result.put(e.getName(), new JSONArray());
				  result.getJSONArray(e.getName()).put(elementToJson(e));
			  }
		  }
	  }
	  return result;
}

     //文件转base64
     public static String encodeBase64File(String path) throws Exception {
	  File file = new File(path);;
	  FileInputStream inputFile = new FileInputStream(file);
	  byte[] buffer = new byte[(int) file.length()];
	  inputFile.read(buffer);
	  inputFile.close();
	  return new BASE64Encoder().encode(buffer);
	 }
	 /**
	  * 将base64字符解码保存文件
	  * @param base64Code
	  * @param targetPath
	  * @throws Exception
	  */
	 public static void decoderBase64File(String base64Code, String targetPath)
	   throws Exception {
	  byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
	  FileOutputStream out = new FileOutputStream(targetPath);
	  out.write(buffer);
	  out.close();
	 }
	 /**
	  * 将base64字符保存文本文件
	  * @param base64Code
	  * @param targetPath
	  * @throws Exception
	  */
	 public static void toFile(String base64Code, String targetPath)
	   throws Exception {
	  byte[] buffer = base64Code.getBytes();
	  FileOutputStream out = new FileOutputStream(targetPath);
	  out.write(buffer);
	  out.close();
	 }


%>